<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Dashboard Template for Bootstrap</title>
    <!-- 小图标 -->
    <link rel="shortcut icon" th:href="@{/resources/favicon.ico}"/>
    <link rel="bookmark" th:href="@{/resources/favicon.ico}"/>

    <!-- Bootstrap core CSS -->
    <link href="/webjars/bootstrap/4.3.1/css/bootstrap.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link th:href="@{/asserts/css/dashboard.css}" rel="stylesheet">
    <style type="text/css">
        /* Chart.js */

        @-webkit-keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        @keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        .chartjs-render-monitor {
            -webkit-animation: chartjs-render-animation 0.001s;
            animation: chartjs-render-animation 0.001s;
        }
    </style>
</head>

<body>
    <!-- 引入顶部栏 -->
    <div th:replace="commons/bar::topbar"></div>

    <div class="container-fluid">
        <div class="row">
            <!-- 引入侧边栏 -->
            <div th:replace="commons/bar::#sidebar(activeUri='users')"></div>

            <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
                <h2 th:if="${session.login_usrid == 0}">用户管理 | <a class="btn btn-sm btn-success"
                              onclick="return userAddView( $('#user_source').val(), $('#token').val() )">用户添加</a></h2>
                <h2 th:if="${session.login_usrid != 0}">学校管理员 | <a class="btn btn-sm btn-success"
                              onclick="return userAddView( $('#user_source').val(), $('#token').val() )">管理员添加</a></h2>

                <div class="table-responsive">
                    <table class="table table-striped table-sm">
                        <thead>
                            <tr>
                                <th>id</th>
                                <th>name</th>
                                <th>role</th>
                                <th>privilege</th>
                                <th>school</th>
                                <th>position</th>
                                <th>phone</th>
                                <th>operator</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr th:each="user : ${userData.rows}">
                                <td th:text="${user.pUid}"></td>
                                <td th:text="${user.name}"></td>
                                <td th:text="${user.role} == 0 ? 'root' : '管理员'">"></td>
                                <td th:text="${user.privilege} == 0 ? '省级' : '校级'"></td>
                                <td th:text="${user.uinfo.school == null ? '无' : user.uinfo.school.name}"></td>
                                <td th:text="${user.uinfo.position}"></td>
                                <td th:text="${#strings.isEmpty(user.uinfo.phone) ? '无' : user.uinfo.phone}"></td>
                                <td>
                                    <a class="btn btn-sm btn-primary" href="#"
                                       th:onclick="'return userEditView(' + ${session.login_usrid} + ',' + '\'' + ${_csrf.token} + '\'' + ','  + ${user.pUid} + ')'">编辑</a>
                                    <button href="#" class="btn btn-sm btn-danger deleteBtn"
                                            th:onclick="'return userRm(' + ${session.login_usrid} + ',' + '\'' + ${_csrf.token} + '\'' + ','  + ${user.pUid} + ')'">删除</button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <h3 th:if="${userData.total == 0 && session.login_usrid != 0}" align="center">
                        <font color="red">您的学校还未有任何管理员，请先添加...</font>
                    </h3>
                    <h3 th:if="${userData.total == 0 && session.login_usrid == 0}" align="center">
                        <font color="red">这里数据空空如也，请在右下角选择筛选条件或添加用户...</font>
                    </h3>
                    <p align="right">
                        <input type="checkbox" id="onlyRoot_checkbox" onchange="return onlyRootChange()"
                            th:checked="${userOnlyRoot == 1} ? 'checked'" th:if="${session.login_usrid == 0}" th:text="只查看超级用户" />
                        <a id="sheng_privilege_a" th:class="${userPrivilege == 0 ? 'btn btn-sm btn-primary' : 'btn btn-sm btn-success'}" href="#" th:if="${session.login_usrid == 0 && (userOnlyRoot == 0 || userOnlyRoot == null)}"
                           onclick="return users( $('#user_source').val(), $('#token').val(), 0, 0 )">省级</a>
                        <a id="sheng_privilege_a" th:class="${userPrivilege == 0 ? 'btn btn-sm btn-primary' : 'btn btn-sm btn-success'}" href="#" th:if="${session.login_usrid == 0 && userOnlyRoot == 1}"
                           onclick="return users( $('#user_source').val(), $('#token').val(), 0, 1 )">省级</a>
                        <a id="xiao_privilege_a" th:class="${userPrivilege == 1 ? 'btn btn-sm btn-primary' : 'btn btn-sm btn-success'}" href="#" th:if="${session.login_usrid == 0 && (userOnlyRoot == 0 || userOnlyRoot == null)}"
                           onclick="return users( $('#user_source').val(), $('#token').val(), 1, 0 )">校级</a>
                        <a id="xiao_privilege_a" th:class="${userPrivilege == 1 ? 'btn btn-sm btn-primary' : 'btn btn-sm btn-success'}" href="#" th:if="${session.login_usrid == 0 && userOnlyRoot == 1}"
                           onclick="return users( $('#user_source').val(), $('#token').val(), 1, 1 )">校级</a>
                    <p/>
                </div>
            </main>
            <form id="deleteEmpForm" method="post">
                <input type="hidden" name="_method" value="delete">
            </form>
        </div>
    </div>

    <!-- 引入公共的js  -->
    <div th:replace="commons/js::js"></div>
    <!-- 自定义的js -->
    <script type="text/javascript" th:src="@{/asserts/js/commons.js}" ></script>
    <script type="text/javascript" th:src="@{/asserts/js/user.js}" ></script>

</body>
</html>